#!/bin/sh
#bnb toppic data import to db

#date 2012-06-04
#author taoran.xu


PDATE=`/bin/date -d 'last day' +%F`
LOGFILE=/export/tmp/bnb_top"$PDATE".log
LOGDATA=/export/tmp/bnb_top"$PDATE".data
OUTFILE=/export/tmp/bnb_top"$PDATE".sql

wget -O "$LOGDATA" -o "$LOGFILE"  http://bnb.qunar.com/render/bnbData.jsp
echo "delete from bnb_toppic where reportdate='"$PDATE"';" > $OUTFILE
cat "$LOGDATA" | awk -F'[][]' '{print $2}' |awk -F '},' '{i = 1;while(i < NF){print $i;i++} }' |awk -F'[{,]' '{for(i = 2; i <= NF;i ++){ str=gsub(/"/,"",$i);split($i,arr,":");brr[arr[1]]=arr[2]; }print "insert into bnb_toppic(reportdate,cityCode,hotelSeq,hasTopPic,hasUGC,hasTag,hasBoss,hasBossName,hasBossInfo) values ('\''""'"$PDATE"'""'\'','\''" brr["cityCode"]"'\'','\''"brr["hotelSeq"]"'\'','\''"brr["hasTopPic"]"'\'','\''"brr["hasUGC"]"'\'','\''"brr["hasTag"]"'\'','\''"brr["hasBoss"]"'\'','\''"brr["hasBossName"]"'\'','\''"brr["hasBossInfo"]"'\'');"; }'>>$OUTFILE
mysql -u qunarlog -p2HhxtsSel6rg -h 192.168.0.253 logstat --default-character-set=utf8 < $OUTFILE

